/*
 * @(#)IntVariable.java
 */
package jp.ac.kobe_u.cs.cream;

import jp.ac.kobe_u.cs.cream.*;
import java.util.*;

/**
 * Integer variables.
 * @see	IntDomain
 * @since 1.0
 * @version 1.0, 01/31/03
 * @author Naoyuki Tamura (tamura@kobe-u.ac.jp)
 */
public class IntVariable extends Variable {

    /**
     * Constructs an integer variable of the network
     * with an initial integer domain <tt>d</tt>
     * and a default name.
     * This constructor is equivalent to <tt>IntVariable(network, d, null)</tt>.
     * @param net the network
     * @param d the initial integer domain
     */
    public IntVariable(Network net, IntDomain d) {
	this(net, d, null);
    }

    /**
     * Constructs an integer variable of the network
     * with an initial integer domain <tt>d</tt>
     * and a name specified by the parameter <tt>name</tt>.
     * When the parameter <tt>name</tt> is <tt>null</tt>,
     * default names (<tt>v1</tt>, <tt>v2</tt>, and so on) are used.
     * @param net the network
     * @param d the initial integer domain
     * @param name the name of the variable, or <tt>null</tt> for a default name
     */
    public IntVariable(Network net, IntDomain d, String name) {
	super(net, d, name);
    }

    public IntVariable(Network net) {
	this(net, IntDomain.FULL);
    }

    public IntVariable(Network net, int value) {
	this(net, new IntDomain(value));
    }

    public IntVariable(Network net, int value, String name) {
	this(net, new IntDomain(value), name);
    }

    public IntVariable(Network net, int lo, int hi) {
	this(net, new IntDomain(lo, hi));
    }

    public IntVariable(Network net, int lo, int hi, String name) {
	this(net, new IntDomain(lo, hi), name);
    }

    public IntVariable add(IntVariable v) {
	Network net = getNetwork();
	IntVariable x = new IntVariable(net);
	// x = this + v
	new IntArith(net, IntArith.ADD, x, this, v);
	return x;
    }

    public IntVariable add(int value) {
	Network net = getNetwork();
	IntVariable x = new IntVariable(net);
	// x = this + value
	new IntArith(net, IntArith.ADD, x, this, new IntVariable(net, value));
	return x;
    }

    public IntVariable subtract(IntVariable v) {
	Network net = getNetwork();
	IntVariable x = new IntVariable(net);
	// x = this - v
	new IntArith(net, IntArith.SUBTRACT, x, this, v);
	return x;
    }

    public IntVariable subtract(int value) {
	Network net = getNetwork();
	IntVariable x = new IntVariable(net);
	// x = this - value
	new IntArith(net, IntArith.SUBTRACT, x, this, new IntVariable(net, value));
	return x;
    }

    public IntVariable multiply(IntVariable v) {
	Network net = getNetwork();
	IntVariable x = new IntVariable(net);
	// x = this * v
	new IntArith(net, IntArith.MULTIPLY, x, this, v);
	return x;
    }

    public IntVariable multiply(int value) {
	Network net = getNetwork();
	IntVariable x = new IntVariable(net);
	// x = this * value
	new IntArith(net, IntArith.MULTIPLY, x, this, new IntVariable(net, value));
	return x;
    }

    public IntVariable max(IntVariable v) {
	Network net = getNetwork();
	IntVariable x = new IntVariable(net);
	// x = max(this, v)
	new IntArith(net, IntArith.MAX, x, this, v);
	return x;
    }

    public IntVariable max(int value) {
	Network net = getNetwork();
	IntVariable x = new IntVariable(net);
	// x = max(this, value)
	new IntArith(net, IntArith.MAX, x, this, new IntVariable(net, value));
	return x;
    }

    public IntVariable min(IntVariable v) {
	Network net = getNetwork();
	IntVariable x = new IntVariable(net);
	// x = min(this, v)
	new IntArith(net, IntArith.MIN, x, this, v);
	return x;
    }

    public IntVariable min(int value) {
	Network net = getNetwork();
	IntVariable x = new IntVariable(net);
	// x = min(this, value)
	new IntArith(net, IntArith.MIN, x, this, new IntVariable(net, value));
	return x;
    }

    public IntVariable negate() {
	Network net = getNetwork();
	IntVariable x = new IntVariable(net);
	// x = - this
	new IntFunc(net, IntFunc.NEGATE, x, this);
	return x;
    }

    public IntVariable abs() {
	Network net = getNetwork();
	IntVariable x = new IntVariable(net);
	// x = abs(this)
	new IntFunc(net, IntFunc.ABS, x, this);
	return x;
    }

    public IntVariable sign() {
	Network net = getNetwork();
	IntVariable x = new IntVariable(net);
	// x = sign(this)
	new IntFunc(net, IntFunc.SIGN, x, this);
	return x;
    }

    public void equals(IntVariable v) {
	Network net = getNetwork();
	new Equals(net, this, v);
    }

    public void equals(int value) {
	Network net = getNetwork();
	new Equals(net, this, new IntVariable(net, value));
    }

    public void notEquals(IntVariable v) {
	Network net = getNetwork();
	new NotEquals(net, this, v);
    }

    public void notEquals(int value) {
	Network net = getNetwork();
	new NotEquals(net, this, new IntVariable(net, value));
    }

    public void le(IntVariable v) {
	Network net = getNetwork();
	new IntComparison(net, IntComparison.LE, this, v);
    }

    public void le(int value) {
	Network net = getNetwork();
	new IntComparison(net, IntComparison.LE, this, new IntVariable(net, value));
    }

    public void lt(IntVariable v) {
	Network net = getNetwork();
	new IntComparison(net, IntComparison.LT, this, v);
    }

    public void lt(int value) {
	Network net = getNetwork();
	new IntComparison(net, IntComparison.LT, this, new IntVariable(net, value));
    }

    public void ge(IntVariable v) {
	Network net = getNetwork();
	new IntComparison(net, IntComparison.GE, this, v);
    }

    public void ge(int value) {
	Network net = getNetwork();
	new IntComparison(net, IntComparison.GE, this, new IntVariable(net, value));
    }

    public void gt(IntVariable v) {
	Network net = getNetwork();
	new IntComparison(net, IntComparison.GT, this, v);
    }

    public void gt(int value) {
	Network net = getNetwork();
	new IntComparison(net, IntComparison.GT, this, new IntVariable(net, value));
    }
}

